package com.example.xd.permissionlibrary

import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import com.example.xd.permissionlibrary.utils.toast

class PermissionActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_permission)
        val permissions = intent.getStringArrayExtra("permission")
        ActivityCompat.requestPermissions(this, permissions, 1)

    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,//所请求的权限
        grantResults: IntArray//相应权限的授予结果
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        for (s in permissions) {
            Log.i("xd---", s)
        }
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            toast(this, "权限获取成功")
            finish()
        } else {
            toast(this, "权限获取失败")
            finish()
        }
    }
}